package com.dmwork.service.interaction.controller.admin;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dmwork.common.base.result.R;
import com.dmwork.service.interaction.entity.CmsBackground;
import com.dmwork.service.interaction.service.CmsBackgroundService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 网页图片内容表 前端控制器
 * </p>
 *
 * @author 李天
 * @since 2021-06-03
 */
@RestController
@RequestMapping("/admin/dm_work/interaction/cms_background")
public class AdminCmsBackgroundController {

    @Autowired
    private CmsBackgroundService cmsBackgroundService;

    @Autowired
    private RedisTemplate redisTemplate;



    @ApiOperation("添加新信息区域背景的信息")
    @PostMapping("add_background")
    public R addBackground(@RequestBody CmsBackground cmsBackground) {
        cmsBackgroundService.save(cmsBackground);
        return R.ok().message("添加成功");
    }


    @ApiOperation("获取网站各区域的背景图片的列表")
    @GetMapping("get_background_list/{page}/{limit}")
    public R getBackgroundList(@PathVariable Integer page, @PathVariable Integer limit) {
        Page<CmsBackground> backgroundPage = new Page<>(page, limit);
        backgroundPage = cmsBackgroundService.page(backgroundPage);
        return R.ok().data("total", backgroundPage.getTotal()).data("rows", backgroundPage.getRecords());
    }

    @ApiOperation("获取指定区域背景的信息")
    @GetMapping("get_background/{locationId}")
    public R getBackground(@PathVariable String locationId) {
        CmsBackground background = cmsBackgroundService.getById(locationId);
        return R.ok().data("item", background);
    }

    @ApiOperation("修改指定区域背景图片的信息")
    @PutMapping("modify_background")
    public R modifyBackground(@RequestBody CmsBackground cmsBackground) {
        cmsBackgroundService.updateById(cmsBackground);

        return R.ok().message("修改成功");
    }

    @ApiOperation("删除指定区域背景信息")
    @DeleteMapping("remove_background/{locationId}")
    public R removeBackground(@PathVariable String locationId) {
        cmsBackgroundService.removeById(locationId);
        return R.ok().message("删除成功");
    }

}

